import 'package:ft_reader/blocs/base_bloc.dart';
import 'package:rxdart/rxdart.dart';
import 'package:ft_reader/beans/book_bean.dart';

class BookBlock extends BaseBloc {

  final _bookBeanFetch = PublishSubject<List<BookBean>>();

  // 监听
  Observable<List<BookBean>> get bookItems => _bookBeanFetch.stream;

  void fetchBookBeans(String categoryId, String kind, int curPage) async {
    List<BookBean> datas = await netApi.fetchCategoryRankData(categoryId, kind, curPage);
    if (!_bookBeanFetch.isClosed) {
      _bookBeanFetch.sink.add(datas);
    }
  }

  void fetchBookRank (
      String categoryId, String kind, String time, int curPage ) async {
    List<BookBean> datas =
    await netApi.fetchRankData(categoryId, kind, time, curPage);
    if (!_bookBeanFetch.isClosed) {
      _bookBeanFetch.sink.add(datas);
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _bookBeanFetch?.close();
  }
}
